package com.russell.pms.dao.hibernate;

import java.util.List;

import com.russell.pms.dao.MaintenanceDao;
import com.russell.pms.model.Maintenance;

/**
 * 
 * @author <a href="mailto:fvinluan@gmail.com">Francis Vinluan</a>
 * 
 * @version $Revision: 1.0 $
 */
public class MaintenanceDaoHibernate extends BaseDaoHibernate implements
		MaintenanceDao {

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.princess.etrak.dao.MaintenanceDao#getMaintenance(java.lang.Short)
	 */
	/**
	 * Method getMaintenance.
	 * 
	 * @param id
	 *            Long
	 * 
	 * @return Maintenance * @see
	 *         com.princess.etrak.dao.MaintenanceDao#getMaintenance(Long) * @see
	 *         com.princess.etrak.dao.MaintenanceDao#getMaintenance(String) * @see
	 *         com.princess.etrak.dao.MaintenanceDao#getMaintenance(String)
	 */
	public Maintenance getMaintenance(int id) {
		if (logger.isDebugEnabled()) {
			logger.debug("getting maintenance begins" + id);
		}
		Maintenance maintenance = (Maintenance) getCurrentSession().get(
				Maintenance.class, id);
		if (logger.isDebugEnabled()) {
			logger.debug("getting maintenance ends ");
		}
		return maintenance;
	}

	/**
	 * Gets a list of all maintenance.
	 * 
	 * 
	 * @return List populated list of maintenance * @see
	 *         com.princess.etrak.dao.MaintenanceDao#getMaintenanceList() * @see
	 *         com.princess.etrak.dao.MaintenanceDao#getMaintenanceList() * @see
	 *         com.princess.etrak.dao.MaintenanceDao#getMaintenanceList() * @see
	 *         com.princess.etrak.dao.MaintenanceDao#getMaintenanceList()
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<Maintenance> getMaintenanceList() {
		if (logger.isDebugEnabled()) {
			logger.debug("getting all maintenance begins");
		}
		List<Maintenance> cList = getCurrentSession().createQuery(
				"FROM Maintenance").list();
		if (cList == null || cList.size() < 1)
			return null;
		if (logger.isDebugEnabled()) {
			logger.debug("getting all maintenance ends: ");
		}
		return cList;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.princess.etrak.dao.MaintenanceDao#removeMaintenance(com.princess.ilo
	 * .model.Maintenance)
	 */
	/**
	 * Method removeMaintenance.
	 * 
	 * @param maintenance
	 *            Maintenance
	 * 
	 * @see com.princess.etrak.dao.MaintenanceDao#removeMaintenance(Maintenance)
	 */
	public void removeMaintenance(Maintenance maintenance) {
		if (logger.isDebugEnabled()) {
			logger.debug("removeMaintenance begins");
		}
		getCurrentSession().delete(maintenance);
		if (logger.isDebugEnabled()) {
			logger.debug("removeMaintenance ends");
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.princess.etrak.dao.MaintenanceDao#saveMaintenance(com.princess.etrak.
	 * model.Maintenance)
	 */
	/**
	 * Method saveMaintenance.
	 * 
	 * @param maintenance
	 *            Maintenance
	 * 
	 * @see com.princess.etrak.dao.MaintenanceDao#saveMaintenance(Maintenance)
	 */
	public void saveMaintenance(Maintenance maintenance) {
		if (logger.isDebugEnabled()) {
			logger.debug("saveMaintenance begins: " + maintenance);
		}
		getCurrentSession().save(maintenance);
		if (logger.isDebugEnabled()) {
			logger.debug("saveMaintenance ends");
		}
	}

	/**
	 * Method updateMaintenance.
	 * 
	 * @param maintenance
	 *            Maintenance
	 * 
	 * @see com.princess.etrak.dao.MaintenanceDao#updateMaintenance(Maintenance)
	 */
	@Override
	public void updateMaintenance(Maintenance maintenance) {
		if (logger.isDebugEnabled()) {
			logger.debug("updateMaintenance begins: " + maintenance);
		}
		getCurrentSession().update(maintenance);
		if (logger.isDebugEnabled()) {
			logger.debug("updateMaintenance ends");
		}
	}

}
